<template>

  <div>
    <div class="margin-container-list">
      <!--顶部搜索 -->
      <div class="top-operate">
        <div>
          <div>
            <el-input style="width: 200px;" v-model="order.textValue" placeholder="订单号"></el-input>
            <el-button type="primary" plain @click="handleSearch">查询</el-button>
            <el-button plain="" @click="resetSearch">重置</el-button>
          </div>
        </div>
      </div>
      <!-- 内容列表 -->
      <div class="table-container">
        <el-table ref="multipleTable" :data="orderList" v-loading="listLoading"
                   element-loading-text="加载中" style="width: 100%" >
          <el-table-column min-width="350px" label="订单信息">
            <template slot-scope="scope">
              <div class="flex v-align-c cursor-p">
                <label v-if="scope.row.goodsImageUrl"><img :src="scope.row.goodsImageUrl" class="mini-pic"></label>
                <div v-if="scope.row.goodsTitle" class="font-12 pad-l-10">
                  <div>{{scope.row.goodsTitle}}</div>
                  <div v-if="scope.row.skuDetail" style="font-size: 10px;color: #3187fd;">{{scope.row.skuDetail}}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column width="185px" label="订单号" align="center" prop="orderNo"></el-table-column>
          <el-table-column width="135px" label="收货人" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.customerNickname" class="pad-l-10">
                <div>{{scope.row.customerNickname}}</div>
                <div v-if="scope.row.customerPhone" style="font-size: 10px;">{{scope.row.customerPhone}}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column width="100px" label="商品数量" align="center" prop="goodsNum">
          </el-table-column>
          <el-table-column width="120px" label="订单分销金额" prop="actualPrice" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.distributeTotalPrice" class="pad-l-10">
                <div>￥{{scope.row.distributeTotalPrice}}</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 列表分页 -->
      <div class="pagination">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="searchListQuery.currentPage"
                       :page-sizes="[10, 20, 50, 100]" :page-size="searchListQuery.size"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .mini-pic {
    width: 68px;
    height: 68px;
    display: block;
    padding: 1px;
    border: #efefef 1px solid;
  }
</style>

<script>
  import { pageProjectOrder } from '@/api/goods/bat-pay'

  export default {
    data() {
      return {
        total: 0,
        listLoading: true,
        searchListQuery: {
        },
        defaultQuery: {
          enterpriseId: this.getEnterpriseId(),
          batPayId: '',
          orderType: 30,
          currentPage: 1,
          size: 10
        },
        order: {
          orderStatus: '1',
          textCol: 'orderNo',
          textValue: '',
          isNotice: false
        },
        dict: {
        },
        orderList: []
      }
    },
    // 初始化页面
    created() {
      const queryParams = this.getCurrentPage().query
      this.defaultQuery.batPayId = queryParams.batPayId
      this.searchListQuery = { ...this.defaultQuery }
      this.init()
    },
    mounted() {
    },
    methods: {
      // 更改当前页数
      handleCurrentChange(val) {
        this.searchListQuery.currentPage = val
        this.init()
      },
      // 更改当前页面大小
      handleSizeChange(val) {
        this.searchListQuery.size = val
        this.init()
      },
      setSearchListQuery() {
        // 搜索状态
        const currentPage = this.searchListQuery.currentPage
        const size = this.searchListQuery.size
        this.searchListQuery = { ... this.defaultQuery }
        this.searchListQuery.enterpriseId = this.getEnterpriseId()
        this.searchListQuery.currentPage = currentPage
        this.searchListQuery.page = currentPage
        this.searchListQuery.size = size
        this.searchListQuery[this.order.textCol] = this.order.textValue
      },
      init() {
        this.setSearchListQuery()
        pageProjectOrder(this.searchListQuery).then(response => {
          if (response.isError) {
            return
          }
          this.total = response.data.total
          this.orderList = response.data.records
          this.dict = response.data.dict
          this.listLoading = false
        })
      },
      handleSearch() {
        this.init()
      },
      resetSearch() {
        this.searchListQuery = { ... this.defaultQuery }
        this.order = {
          textCol: 'orderNo',
          textValue: '',
          village: '',
          memberVillageId: ''
        }
        this.init()
      }
    }
  }

</script>
